/*
 * Main.fx
 *
 * Created on 01/12/2010, 09:45:01
 */

package evabot.main;

import evabot.facade.BotFacade;
import java.util.Date;
import java.lang.System;
//import java.lang.System;

/**
 * @author Alexandre
 */
public class Main {

    var fileName;
    var facade:BotFacade = new BotFacade();
    
    var message = "";
    var bot = "Eva";
    var nickName = "Eu";

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:main
    public-read def labelNome: javafx.scene.control.Label = javafx.scene.control.Label {
        layoutX: 6.0
        layoutY: 12.0
        text: "Nome:"
    }
    
    def __layoutInfo_textBoxNome: javafx.scene.layout.LayoutInfo = javafx.scene.layout.LayoutInfo {
        width: 299.0
    }
    public-read def textBoxNome: javafx.scene.control.TextBox = javafx.scene.control.TextBox {
        layoutX: 44.0
        layoutY: 6.0
        layoutInfo: __layoutInfo_textBoxNome
    }
    
    def __layoutInfo_buttonStart: javafx.scene.layout.LayoutInfo = javafx.scene.layout.LayoutInfo {
        width: 56.0
    }
    public-read def buttonStart: javafx.scene.control.Button = javafx.scene.control.Button {
        layoutX: 351.0
        layoutY: 7.0
        layoutInfo: __layoutInfo_buttonStart
        text: "Start"
        action: buttonStartAction
    }
    
    def __layoutInfo_buttonClose: javafx.scene.layout.LayoutInfo = javafx.scene.layout.LayoutInfo {
        width: 59.0
    }
    public-read def buttonClose: javafx.scene.control.Button = javafx.scene.control.Button {
        layoutX: 413.0
        layoutY: 6.0
        layoutInfo: __layoutInfo_buttonClose
        text: "Close"
        action: buttonCloseAction
    }
    
    public-read def labelQuestion: javafx.scene.control.Label = javafx.scene.control.Label {
        layoutX: 6.0
        layoutY: 297.0
        text: "Question:"
    }
    
    def __layoutInfo_textBoxSendMessage: javafx.scene.layout.LayoutInfo = javafx.scene.layout.LayoutInfo {
        width: 348.0
    }
    public-read def textBoxSendMessage: javafx.scene.control.TextBox = javafx.scene.control.TextBox {
        disable: true
        layoutX: 59.0
        layoutY: 291.0
        layoutInfo: __layoutInfo_textBoxSendMessage
    }
    
    def __layoutInfo_buttonSend: javafx.scene.layout.LayoutInfo = javafx.scene.layout.LayoutInfo {
        width: 59.0
    }
    public-read def buttonSend: javafx.scene.control.Button = javafx.scene.control.Button {
        disable: true
        layoutX: 413.0
        layoutY: 291.0
        layoutInfo: __layoutInfo_buttonSend
        text: "Send"
        action: buttonSendAction
    }
    
    public-read def color: javafx.scene.paint.Color = javafx.scene.paint.Color {
        red: 0.8
        green: 0.8
        blue: 0.8
    }
    
    public-read def color2: javafx.scene.paint.Color = javafx.scene.paint.Color {
        red: 0.0
        green: 1.0
        blue: 1.0
        opacity: 1.0
    }
    
    public-read def font: javafx.scene.text.Font = javafx.scene.text.Font {
    }
    
    def __layoutInfo_textBoxReceiveMessage: javafx.scene.layout.LayoutInfo = javafx.scene.layout.LayoutInfo {
        width: 466.0
        height: 250.0
    }
    public-read def textBoxReceiveMessage: javafx.scene.control.TextBox = javafx.scene.control.TextBox {
        disable: true
        opacity: 1.0
        layoutX: 6.0
        layoutY: 33.0
        layoutInfo: __layoutInfo_textBoxReceiveMessage
        selectOnFocus: false
        editable: false
        font: font
        multiline: true
    }
    
    public-read def color3: javafx.scene.paint.Color = javafx.scene.paint.Color {
        green: 0.7882353
        blue: 1.0
    }
    
    public-read def scene: javafx.scene.Scene = javafx.scene.Scene {
        width: 480.0
        height: 320.0
        content: getDesignRootNodes ()
        fill: color3
    }
    
    public-read def currentState: org.netbeans.javafx.design.DesignState = org.netbeans.javafx.design.DesignState {
    }
    
    public function getDesignRootNodes (): javafx.scene.Node[] {
        [ labelNome, textBoxNome, buttonStart, buttonClose, textBoxReceiveMessage, labelQuestion, textBoxSendMessage, buttonSend, ]
    }
    
    public function getDesignScene (): javafx.scene.Scene {
        scene
    }
    // </editor-fold>//GEN-END:main

    function buttonSendAction(): Void {
        message = textBoxReceiveMessage.text;
        if (message!="") {
            message += "\n";
        }

        message += nickName;
        message += ": ";
        message += textBoxSendMessage.text;
        message += "\n";
        message += bot;
        message += ": ";
        message += facade.botRespond(textBoxSendMessage.text);

        textBoxSendMessage.clear();

        textBoxReceiveMessage.text = message;
        textBoxReceiveMessage.end();
    }

    function buttonCloseAction(): Void {
        
        // envio de email
        facade.createMail("evahbot@gmail.com", "EvaBot", "danicme@gmail.com", "moca", "[BASE DE CONHECIMENTO] nova informacoes", "A base de conhecimento foi modificada", "smtp.gmail.com", "465");
        facade.addCC("alexandreufcg@gmail.com", "Alexandre");
        facade.addCC("mariaifc19@gmail.com", "Bel");
        facade.setSLL();
        facade.setAuthentication("evahbot", "itwol123");
        facade.sendMail();

        // fechando o sistema
        scene.stage.close();
    }

    function buttonStartAction(): Void {
        nickName = textBoxNome.text;
        if (nickName!="") {
            textBoxSendMessage.disable = false;
            buttonSend.disable = false;

            fileName = nickName;
            fileName += "_";
            fileName += new Date(System.currentTimeMillis()).toString();
            fileName = fileName.replace(' ', '');
            fileName = fileName.replace(':', '');
            fileName = fileName.replace('-', '');

            facade.createBot("Bot/context.xml", "Bot/splitters.xml", "Bot/substitutions.xml", "Bot/Alice", ".*\\.aiml",fileName);
            facade.setLog(true);
            facade.setFileName(fileName);
            facade.setDeafultResponse("Puxa, que legal! Infelizmente eu nao sei nada sobre o que voce esta falando, mas voce poderia me ajudar a aprender mais sobre isso. Basta escrever assim: Aprenda que ISSO eh AQUILO, substituindo ISSO e AQUILO por o que eu devo aprender.");
            facade.createBlankAIMLFile();

            message = "Eva: Ola ";
            message += nickName;
            message += ", no que posso ajuda?";
            textBoxReceiveMessage.text = message;
        }
    }
}

function run (): void {
    var design = Main {};

    javafx.stage.Stage {
        title: "EvaBot"
        scene: design.getDesignScene ()
    }
}
